package com.android.ailaoshan.user.handle;

import android.content.Context;
import android.content.SharedPreferences;

import java.util.HashMap;
import java.util.Map;

/**
 * 登录过程处理
 */
public class LoginHandler {
    private SharedPreferences mSharedPreferences;

    public LoginHandler(Context mContext) {
        mSharedPreferences = mContext.getSharedPreferences("userLogin",Context.MODE_PRIVATE);
    }

    /**
     * 添加数据
     */
    public void addData(String userName,String userPswd,String tokenId){
        SharedPreferences.Editor editor = mSharedPreferences.edit();

        editor.putString("userName",userName);
        editor.putString("userPswd",userPswd);
        editor.putString("tokenId",tokenId);

        editor.apply();
    }

    /**
     * 读取数据
     */
    public Map<String, String> getData(){
        Map<String,String> userMap = new HashMap<>();

        userMap.put("userName",mSharedPreferences.getString("userName",""));
        userMap.put("userPswd",mSharedPreferences.getString("userPswd",""));
        userMap.put("tokenId",mSharedPreferences.getString("tokenId",""));

        return userMap;
    }

}
